package cn.panda.edu.controller;

import cn.panda.edu.model.Notice;
import cn.panda.edu.service.NoticeService;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value="/api/admin")
@Api(description="公告管理")
public class ManageNoticeController {
	@Autowired
	private NoticeService noticeService;
	
	/**
	 * 
	* @Title: noticemanageFy 
	* @Description: TODO(公告模糊查询分页) 
	* @param @param noticeName
	* @param @param noticeDate
	* @param @param pageIndex
	* @param @return  
	* @return PageInfo<Notice>
	 */
	@ApiOperation(value="公告模糊查询分页" , notes="")//用以指明api名称 
	@ApiImplicitParams({@ApiImplicitParam(name="noticeName", value="公告名称", required=false, dataType="string",paramType="form"),		               
		               @ApiImplicitParam(name="pageIndex", value="页码", required=true, dataType="int",paramType="form")})	
	@RequestMapping(value = "/noticemanageFy",method = RequestMethod.POST)
	public Object noticemanageFy(@RequestParam(required=false)String condition, Integer pageIndex){
		PageInfo<Notice> pageInfo=noticeService.selectLikeByPrimaryKey(condition, null, pageIndex);
		return ResultDataUtil.resData(200, "", pageInfo);		
	}
	/**
	 * 
	* @Title: noticemanageAdd                                                                 
	* @Description: (添加公告) 
	* @param @param notice
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="添加公告" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="notice", value="公告对象", required=true, dataType="Notice",paramType="form")	
	@RequestMapping(value = "/noticemanageAdd",method = RequestMethod.POST)
	public Map<String,Object> noticemanageAdd(@RequestParam(required=true)Notice notice){
		Map<String,Object> map=new HashMap<>();
		int i=noticeService.insertSelective(notice);
		if(i>0) {
			map = ResultDataUtil.resData(200, "添加成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "添加失败",null) ;
		}
		return map;		
	}
	
	/**
	 * 
	* @Title: noticemanageSel 
	* @Description: TODO(根据主键查询公告) 
	* @param @param noticeId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据主键查询公告" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="noticeId", value="公告id", required=true, dataType="int",paramType="form")	
	@RequestMapping(value = "/noticemanageSel",method = RequestMethod.POST)
	public Map<String,Object> noticemanageSel(@RequestParam(required=true)Integer noticeId){
		Notice notice=noticeService.selectByPrimaryKey(noticeId);		
		return ResultDataUtil.resData(200, "", notice);		
	}
	
	/**
	 * 
	* @Title: noticemanageDel 
	* @Description: TODO(根据主键删除公告) 
	* @param @param noticeId
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="根据主键删除公告" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="noticeId", value="公告id", required=true, dataType="int",paramType="form")	
	@RequestMapping(value = "/noticemanageDel",method = RequestMethod.POST)
	public Map<String,Object> noticemanageDel(@RequestParam(required=true)Integer noticeId){
		Map<String,Object> map=new HashMap<>();
		int i=noticeService.deleteByPrimaryKey(noticeId);
		if(i>0) {
			map = ResultDataUtil.resData(200, "删除成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "删除成功",null) ;
		}
		return map;		
	}
	
	/**
	 * 
	* @Title: noticemanageUp 
	* @Description: TODO(修改公告) 
	* @param @param notice
	* @param @return  
	* @return Map<String,Object>
	 */
	@ApiOperation(value="修改公告" , notes="")//用以指明api名称 
	@ApiImplicitParam(name="notice", value="公告对象", required=true, dataType="Notice",paramType="form")	
	@RequestMapping(value = "/noticemanageUp",method = RequestMethod.POST)
	public Map<String,Object> noticemanageUp(@RequestParam(required=true)Notice notice){
		Map<String,Object> map=new HashMap<>();
		int i=noticeService.updateByPrimaryKeySelective(notice);
		if(i>0) {
			map = ResultDataUtil.resData(200, "修改成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "修改失败",null) ;
		}
		return map;		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
